<template>
    <div style="width:100%;height:100%">
        <div class="login-wrap">
            <div class="ms-login">
                <!--<div class="ms-logo"></div>-->
                <div class="ms-title">管理系统</div>
                <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                    <el-form-item prop="account">
                        <el-input v-model="param.account" placeholder="account">
                            <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input
                            type="password"
                            placeholder="password"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                        >
                            <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                        </el-input>
                    </el-form-item>
                    <div class="login-btn">
                        <el-button type="primary" @click="submitForm()">登录</el-button>
                    </div>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data: function() {
        return {
            isMobile:this.$isMobile,
            param: {
                account: '',
                password: '',
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
        };
    },
    mounted(){},
    methods: {
        submitForm() {
            const loading = this.$loading({text: '登录中'});
            this.$http.post(this.$API.LOGIN,this.param)
            .then((res)=>{
                loading.close();
                console.log('登录信息',res)
                if(res.code == 1){
                   window.sessionStorage.setItem('jqzxUserId', res.data.id)
                    window.sessionStorage.setItem('userName',res.data.account);
                    window.localStorage.setItem('userInfo',JSON.stringify(res.data));
                    if(this.isMobile){
                        Toast.success('登录成功');
                    }else{
                        this.$message.success('登录成功');
                    }
                    this.$router.push('/');
                }else{
                    if(this.isMobile){
                        Toast.fail(res.msg);
                    }else{
                        this.$message.error(res.msg);
                    }
                }
            })
            .catch((err)=>{
                    this.$message.error('');
                    console.log('error submit!!');
                    return false;
            })
        },
        getQueryVariable(variable) {
            var query = window.location.hash,vars=[];
            if(query && query.indexOf('?')!==-1){
                 vars = query.split("?");
            }
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return decodeURIComponent(pair[1]); }
            }
            return '';
        }
    },
};
</script>

<style scoped>
.login-mobile-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background: #409EFF;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ms-mobile-login{
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
    width: 85%;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background: url('../../assets/img/login-bg.png') center no-repeat;
    background-size: 100% 100%;
}
.el-button--primary{
  background-color: #db511f;
  border-color: #db511f;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #db511f;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
}
.ms-logo{
  height: 50px;
  background: url('../assets/img/logo.png') center no-repeat;
  background-size: auto 50px;
}
.ms-login {
    position: absolute;
    right: 20%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    padding-top:20px;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
    font-size: 0;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>